//
// Created by sgyt on 2020/1/18.
// 时间精确

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc,char *argv[])
{
    struct timespec time1,time2,time3;
    int res;
    //根据timespec获取精度
    clockid_t ct;
    time3.tv_sec = 0;
    time3.tv_nsec = 1000000;
    clock_getres(ct,&time3);
    res = clock_gettime(ct,&time3);
    printf("timeSec = [%d],timM = [%d]\n",time3.tv_sec,time3.tv_nsec);


    res = clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&time1);
    printf("timeSec = [%d],timM = [%d]\n",time1.tv_sec,time1.tv_nsec);
    int  i = 0;
    long k = 0;
    for(i= 0;i<100000;i++)
    {
        k = k+i;
    }
    res = clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&time2);
    printf("timeSec = [%d],timM = [%d]\n",time2.tv_sec,time2.tv_nsec);
    return 0;
}